package imnu.th.stop;

/**
 * @author: lys
 * @类名: MyThread
 * @Title:
 * @date: 2020/7/22
 **/
public class MyThread extends Thread {
    //设置中止变量
    private boolean stopped;

    public MyThread() {
    }

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        int i=0;
        for (;;){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(this.getName()+"-----"+i++);
            //判断线程是否中止
            if (stopped){
                break;
            }
        }
    }

    public boolean isStopped() {
        return stopped;
    }

    public void setStopped(boolean stopped) {
        this.stopped = stopped;
    }
}
